#include <stdio.h>

int main()
{
    int T, t;
    scanf("%d", &T);
    for (t = 0; t < T; t++)
    {
        int left_queue = 0, right_queue = 0;
        int left_times = 0, right_times = 0, times;
        int ferry_len, num_cars, i;
        scanf("%d %d", &ferry_len, &num_cars);
        ferry_len *= 100; /* meter to centimeter */
        for (i = 0; i < num_cars; i++)
        {
            int car_len;
            char side[10];
            scanf("%d %s", &car_len, side);
            if (side[0] == 'l') /* left bank */
            {
                if (left_queue + car_len > ferry_len)
                {
                    left_times++;
                    left_queue = 0;
                }
                left_queue += car_len;
            }
            else                /* right bank */
            {
                if (right_queue + car_len > ferry_len)
                {
                    right_times++;
                    right_queue = 0;
                }
                right_queue += car_len;
            }
        }
        if (left_queue > 0)
            left_times++;
        if (right_queue > 0)
            right_times++;
        
        if (left_times <= right_times)
            times = right_times * 2;
        else /* left_times > right_times */
            times = left_times * 2 - 1;
        printf("%d\n", times);
    }
    return 0;
}